﻿//-----------------------------------------------------------------------------
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Microsoft.LibraryManagerDemo.Controls
{
    /// <summary>
    /// Represents a window host for views/presenters in the MVVM pattern.
    /// </summary>
    /// <remarks>
    /// This helper class is used for displaying non-window views/presenters as a skin-aware window.
    /// </remarks>
    public partial class ViewHost : Window
    {
        #region Initializers

        public ViewHost()
        {
            DataContext = this;
            InitializeComponent();
        }
        
        #endregion

        #region Dependency Properties

        /// <summary>
        /// Gets or sets the view to wrap.
        /// </summary>
        public object View
        {
            get { return (object)GetValue(ViewProperty); }
            set { SetValue(ViewProperty, value); }
        }

        // Using a DependencyProperty as the backing store for View.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ViewProperty =
            DependencyProperty.Register(
                "View",
                typeof(object),
                typeof(ViewHost),
                new UIPropertyMetadata(null, ViewPropertyChanged));

        private static void ViewPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var view = e.NewValue as FrameworkElement;
            if (view != null)
            {
                view.Focus();
            }
        }

        #endregion

        #region Event Handlers

        private void ButtonOK_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
        }
        
        #endregion
    }
}
